home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Binary upload download processor *)
- (* *)
- (* Copyright 1986 Jeffry B. Jacobsen. All rights reserved. *)
- (* Copyright 1989, 1991 by H. Roy Engehausen. All rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$UNDEF DEBUG_OPR}
-
- {$O+}
-
- UNIT BBBIN;
-
- INTERFACE
-
- USES
- bbdummy;
-
- PROCEDURE bin_cmd(cmd_string : STRING);
-
- IMPLEMENTATION
-
- USES
- CRT,
- DOS,
- bbconvm,
- bbcopy,
- bbfsm,
- bblog,
- bblstr,
- bbmdata,
- bbmem,
- bbmess,
- bbmisc,
- bbmisc4,
- bbmisc5,
- bbrdata,
- bbrunerr,
- bbsdata,
- bbsema2,
- bbsess,
- bbstr,
- bbtask,
- bbtime,
- bbwin;
-
- PROCEDURE bin_cmd(cmd_string : STRING);
-
- (*-------------------------------------------------------------------------*)
- (* These are the global vars *)
- (*-------------------------------------------------------------------------*)
-
- TYPE
-
- bin_xfer_type = (bin_unknown,
- bin_xmodem,
- bin_xmodemcrc,
- bin_ymodem,
- bin_ymodem_batch,
- bin_yapp);
-
- VAR
-
- abort_sw : BOOLEAN;
- bin_xfer : bin_xfer_type;
- bin_mode : STRING[15];
- bytes_per_block : WORD;
- code : INTEGER;
- conv_sw : BOOLEAN;
- dir_to_search : fsb_name_str;
- i : WORD;
- look : SEARCHREC;
- p : STRING[4];
- pkfname : file_name_str;
- save_show : BOOLEAN;
- search_arg : file_name_str;
- send_switch : BOOLEAN;
- show_xmit_count : BYTE;
- this_fsb : fsb_ptr;
- this_msg : msg_index_ptr;
- up_it : BOOLEAN;
- word_count : BYTE;
- work_string : STRING[125];
-
- (*=========================================================================*)
- (* External general subroutines *)
- (*=========================================================================*)
-
- {$I BBMACRO.PAS}
- {$I BBFSI.PAS}
- {$I BBBINM.PAS}
-
- (*=========================================================================*)
- (* Binary transfer routines *)
- (*=========================================================================*)
-
- {$I BBYAPP0.PAS}
- {$I BBXYMOD.PAS}
-
- (*=========================================================================*)
- (* Main line *)
- (*=========================================================================*)
-
- BEGIN;
-
- {$IFDEF DEBUG_OPR}
- WRITELN('Bin -- ', cmd_string , ' -- ', active_tcb^.port_chan_s);
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Initialize switches *)
- (*-----------------------------------------------------------------------*)
-
- send_switch := TRUE;
-
- abort_sw := FALSE;
-
- conv_sw := active_tcb^.conv_tcb <> NIL;
-
- p := active_tcb^.port_chan_s + 'B:';
-
- free_task_mem('$1', TRUE);
-
- (*-----------------------------------------------------------------------*)
- (* If this is the operator task, prevent him from doing something *)
- (* stupid. Then pass the command to the conversing task *)
- (*-----------------------------------------------------------------------*)
-
- IF active_tcb^.tcb_type = th_operator THEN
- BEGIN;
-
- {$IFDEF DEBUG_OPR}
- WRITELN('Bin switch task');
- {$ENDIF}
-
- (*-------------------------------------------------------------------*)
- (* Can't transfer with out anybody connected *)
- (*-------------------------------------------------------------------*)
-
- IF NOT conv_sw THEN
- BEGIN;
- send_message(message_need_conv);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-------------------------------------------------------------------*)
- (* Command remote end and leave *)
- (*-------------------------------------------------------------------*)
-
- cmd_string := escape + escape + cmd_string;
- add_c_string(active_tcb^.conv_tcb, @cmd_string, 0);
-
- EXIT;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Parse command *)
- (*-----------------------------------------------------------------------*)
-
- upcase_str_var(cmd_string);
-
- word_count := words(cmd_string);
-
- IF word_count <> 4 THEN
- BEGIN;
- IF word_count < 4 THEN
- do_mess(message_not_en)
- ELSE
- do_mess(message_err_wrd);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Set direction. *)
- (*-----------------------------------------------------------------------*)
-
- up_it := cmd_string[1] = 'U';
-
- (*-----------------------------------------------------------------------*)
- (* Parse *)
- (*-----------------------------------------------------------------------*)
-
- bin_mode := subword(@cmd_string, 2, 1);
-
- dir_to_search := subword(@cmd_string, 3, 1);
-
- search_arg := subword(@cmd_string, 4, 1);
-
- (*-----------------------------------------------------------------------*)
- (* Test the binary file transfer type *)
- (*-----------------------------------------------------------------------*)
-
- bin_xfer := bin_unknown;
- IF bin_mode = 'XMODEM' THEN
- bin_xfer := bin_xmodem;
- IF bin_mode = 'XMODEMCRC' THEN
- bin_xfer := bin_xmodemcrc;
- IF bin_mode = 'YMODEM' THEN
- bin_xfer := bin_ymodem;
- IF bin_mode = 'YMBATCH' THEN
- bin_xfer := bin_ymodem_batch;
- IF bin_mode = 'YMODEM-BATCH' THEN
- bin_xfer := bin_ymodem_batch;
- IF bin_mode = 'YAPP' THEN
- bin_xfer := bin_yapp;
-
- IF bin_xfer = bin_unknown THEN
- BEGIN;
- do_mess(message_bad_bin);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Find the directory *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPR}
- WRITELN('Dir');
- {$ENDIF}
-
- work_string := active_tcb^.port_chan_s + 'B:';
- i := 1 + ORD(active_tcb^.uid_data.user_class);
-
- this_fsb := find_fsb(dir_to_search);
-
- IF (this_fsb = NIL) OR
- (active_tcb^.uid_data.user_class < this_fsb^.fsb_down) THEN
- BEGIN;
-
- IF this_fsb = NIL THEN
- window_write(work_string, 'Unknown data area for transfer')
- ELSE
- window_write(work_string, 'Insufficent authority for download -- '
- + user_class_string[i]);
-
- do_mess(message_no_files_one);
- active_tcb^.error_sw := TRUE;
-
- EXIT;
-
- END;
-
- IF up_it AND (active_tcb^.uid_data.user_class < this_fsb^.fsb_up) THEN
- BEGIN;
-
- window_write(work_string, 'Insufficent authority for upload -- '
- + user_class_string[i]);
-
- do_mess(message_no_files_one);
- active_tcb^.error_sw := TRUE;
-
- EXIT;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Check for subdirectory *)
- (*-----------------------------------------------------------------------*)
-
- IF (POS('\', search_arg) > 0) AND NOT this_fsb^.fsb_f_subdir_ok THEN
- BEGIN;
- do_mess(message_no_slash);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Check for wildcards *)
- (*-----------------------------------------------------------------------*)
-
- IF (POS('*', search_arg) > 0) THEN
- BEGIN;
- do_mess(message_no_wild);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Binary ok? *)
- (*-----------------------------------------------------------------------*)
-
- IF NOT this_fsb^.fsb_binary OR active_port^.port_no_binary THEN
- BEGIN;
- do_mess(message_no_binary);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Build file name *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPR}
- WRITELN('Build name');
- {$ENDIF}
-
- work_string := this_fsb^.fsb_path + search_arg;
-
- (*-----------------------------------------------------------------------*)
- (* Test the file *)
- (*-----------------------------------------------------------------------*)
-
- i := file_test(work_string);
-
- {$IFDEF DEBUG_OPR}
- WRITELN('Filetest -- ', i);
- {$ENDIF}
-
- IF up_it THEN
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* If we are "uploading" it then it must not exist already *)
- (*-------------------------------------------------------------------*)
-
- IF i = 0 THEN
- BEGIN;
- do_mess(message_file_exists);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- END
- ELSE
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* If we are "downloading" then the file MUST exist *)
- (*-------------------------------------------------------------------*)
-
- IF i <> 0 THEN
- BEGIN;
- do_mess(message_file_no_exist);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* All other open errors are caught here *)
- (*-----------------------------------------------------------------------*)
-
- IF (i <> 0) AND (i <> 2) THEN
- BEGIN;
-
- work_string := dos_err_message(i) + cr;
-
- IF conv_sw THEN
- window_write(p, work_string)
- ELSE
- send_tnc_data_str(work_string);
-
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Set block size for YAPP *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPR}
- WRITELN('Block size');
- {$ENDIF}
-
- bytes_per_block := active_tcb^.max_pac;
- IF bytes_per_block > 10 THEN
- DEC(bytes_per_block, 2);
- IF bytes_per_block < 5 THEN
- bytes_per_block := 250;
-
- (*-----------------------------------------------------------------------*)
- (* Get a file block to hold the info *)
- (*-----------------------------------------------------------------------*)
-
- IF active_tcb^.io_fe <> NIL THEN
- BEGIN;
- {$I-}
- CLOSE(active_tcb^.io_fe^.fe_text);
- i := IORESULT;
- {$I+}
- END
- ELSE
- BEGIN;
- NEW(active_tcb^.io_fe);
- FILLCHAR(active_tcb^.io_fe^, SIZEOF(active_tcb^.io_fe^), CHR(0));
- END;
-
- active_tcb^.io_fe^.fe_type := TRUE;
-
- (*-----------------------------------------------------------------------*)
- (* Tell user to start *)
- (*-----------------------------------------------------------------------*)
-
- set_dollar1_parm(@bin_mode);
- do_mess(message_start_bin);
- send_flush;
-
- (*-----------------------------------------------------------------------*)
- (* Obtain the interrupt semaphore *)
- (*-----------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* See if we are sending or receiving *)
- (*-----------------------------------------------------------------------*)
-
- IF NOT up_it THEN
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* Send the file *)
- (*-------------------------------------------------------------------*)
-
- (*-------------------------------------------------------------------*)
- (* Use the file name specified *)
- (*-------------------------------------------------------------------*)
-
- pkfname := work_string;
-
- (*-------------------------------------------------------------------*)
- (* Set the show flags *)
- (*-------------------------------------------------------------------*)
-
- save_show := active_tcb^.tcb_no_show_sdata;
- active_tcb^.tcb_no_show_sdata := NOT opt_block.opt_show_binary;
-
- (*-------------------------------------------------------------------*)
- (* Throw away anything that has arrived *)
- (*-------------------------------------------------------------------*)
-
- flush_input_buffers;
-
- (*-------------------------------------------------------------------*)
- (* Do the download *)
- (*-------------------------------------------------------------------*)
-
- CASE bin_xfer OF
- bin_yapp : yapp_xfer;
- bin_xmodem..bin_ymodem_batch : xy_xfer;
- END;
-
- (*-------------------------------------------------------------------*)
- (* Restore the show/noshow flags *)
- (*-------------------------------------------------------------------*)
-
- active_tcb^.tcb_no_show_sdata := save_show;
-
- (*-------------------------------------------------------------------*)
- (* If we are ok, tell user and log it *)
- (*-------------------------------------------------------------------*)
-
- IF (NOT active_tcb^.error_sw) AND (NOT abort_sw) THEN
- BEGIN;
- do_mess(message_bin_done);
- log_data_s(cmd_string);
- END;
-
- (*-------------------------------------------------------------------*)
- (* Close things *)
- (*-------------------------------------------------------------------*)
-
- close_things_up;
-
- (*-------------------------------------------------------------------*)
- (* Leave things *)
- (*-------------------------------------------------------------------*)
-
- EXIT;
-
- END; (*----- End of IF statement for download -------------------------*)
-
- (*-----------------------------------------------------------------------*)
- (* Build temp file name *)
- (*-----------------------------------------------------------------------*)
-
- pkfname := opt_block.msg_file_dir + active_tcb^.port_chan_s + '.IN';
-
- (*-----------------------------------------------------------------------*)
- (* Set the show switches both for local task and for distant *)
- (*-----------------------------------------------------------------------*)
-
- save_show := active_tcb^.tcb_no_show_sdata;
- active_tcb^.tcb_no_show_sdata := NOT opt_block.opt_show_binary;
-
- (*-----------------------------------------------------------------------*)
- (* Throw away anything received until now *)
- (*-----------------------------------------------------------------------*)
-
- flush_input_buffers;
-
- (*-----------------------------------------------------------------------*)
- (* Receive the file *)
- (*-----------------------------------------------------------------------*)
-
- CASE bin_xfer OF
- bin_yapp : yapp_xfer;
- bin_xmodem..bin_ymodem_batch : xy_xfer;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Restore show switchss *)
- (*-----------------------------------------------------------------------*)
-
- active_tcb^.tcb_no_show_sdata := save_show;
-
- (*-----------------------------------------------------------------------*)
- (* Close things *)
- (*-----------------------------------------------------------------------*)
-
- close_things_up;
-
- (*-----------------------------------------------------------------------*)
- (* If an error has occurred, leave *)
- (*-----------------------------------------------------------------------*)
-
- IF active_tcb^.error_sw OR abort_sw THEN
- EXIT;
-
- (*-----------------------------------------------------------------------*)
- (* Copy file *)
- (*-----------------------------------------------------------------------*)
-
- work_string := copy_file_binary(pkfname, work_string, FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Report any errors *)
- (*-----------------------------------------------------------------------*)
-
- IF work_string <> '' THEN
- BEGIN;
- send_tnc_data_str(work_string + cr);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* No errors! Tell user and logit *)
- (*-----------------------------------------------------------------------*)
-
- do_mess(message_file_saved);
-
- log_data_s(cmd_string);
-
- END;
-
- END.